package org.opens.mybatisplus.controller;

import org.opens.mybatisplus.pojo.FormatPojo;
import org.opens.mybatisplus.service.FormatService;
import org.opens.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping(value = "/api")
public class DateController {

    @Autowired
    private FormatService formatService;

    @RequestMapping(value = "/java8date", method = RequestMethod.GET)
    public R deliveryTime(
            @RequestParam(value = "startDateStr") String startDateStr
    ) {
        R success = R.success("获取成功");
        success.put("date", LocalDate.parse(startDateStr));
        return success;
    }

    @RequestMapping(value = "/java8date/db", method = RequestMethod.GET)
    public R accessDb(
            @RequestParam(value = "startDateStr") String startDateStr
    ) {
        R success = R.success("获取成功");
        List<FormatPojo> formatPojoList = formatService.findByStratDate(startDateStr);
        success.put("data", formatPojoList);
        return success;
    }

}
